home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / helpindx.c < prev    next >
C/C++ Source or Header  |  1996-04-25  |  4KB  |  151 lines

  1. #if !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: helpindx.c,v 4.11 1996/04/25 23:36:30 hubert Exp $";
  3. #endif
  4. /*----------------------------------------------------------------------
  5.  
  6.             T H E    P I N E    M A I L   S Y S T E M
  7.  
  8.    Laurence Lundblade and Mike Seibel
  9.    Networks and Distributed Computing
  10.    Computing and Communications
  11.    University of Washington
  12.    Administration Builiding, AG-44
  13.    Seattle, Washington, 98195, USA
  14.    Internet: lgl@CAC.Washington.EDU
  15.              mikes@CAC.Washington.EDU
  16.  
  17.    Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  18.  
  19.  
  20.    Pine and Pico are registered trademarks of the University of Washington.
  21.    No commercial use of these trademarks may be made without prior written
  22.    permission of the University of Washington.
  23.  
  24.    Pine, Pico, and Pilot software and its included text are Copyright
  25.    1989-1996 by the University of Washington.
  26.  
  27.    The full text of our legal notices is contained in the file called
  28.    CPYRIGHT, included with this distribution.
  29.  
  30.  
  31.    Pine is in part based on The Elm Mail System:
  32.     ***********************************************************************
  33.     *  The Elm Mail System  -  Revision: 2.13                             *
  34.     *                                                                     *
  35.     *             Copyright (c) 1986, 1987 Dave Taylor              *
  36.     *             Copyright (c) 1988, 1989 USENET Community Trust   *
  37.     ***********************************************************************
  38.  
  39.  
  40.   ----------------------------------------------------------------------*/
  41.  
  42. /*
  43.  * very short, very specialized
  44.  *
  45.  *
  46.  *
  47.  */
  48. #include <stdio.h>
  49. #include <ctype.h>
  50.  
  51. #define    HELP_KEY_MAX    64        /* maximum length of a key */
  52.  
  53. struct hindx {
  54.     char  key[HELP_KEY_MAX];        /* name of help section */
  55.     long  offset;            /* where help text starts */
  56.     short lines;            /* how many lines there are */
  57. };
  58.  
  59. main(argc, argv)
  60. int  argc;
  61. char **argv;
  62. {
  63.     char *p, s[256];
  64.     long index;
  65.     int  section, 
  66.      len, 
  67.      line,
  68.      i; 
  69.     FILE *hp,
  70.      *hip,                    /* help index ptr */
  71.          *hhp;                    /* help header ptr */
  72.     struct hindx irec;
  73.  
  74.     if(argc < 4){
  75.     fprintf(stderr,
  76.         "usage: helpindx <help_file> <index_file> <header_file>\n");
  77.     exit(-1);
  78.     }
  79.  
  80.     if((hp = fopen(argv[1], "rb")) == NULL){    /* problems */
  81.     perror(argv[1]);
  82.         exit(-1);
  83.     }
  84.  
  85.     if((hip = fopen(argv[2], "wb")) == NULL){    /* problems */
  86.     perror(argv[2]);
  87.         exit(-1);
  88.     }
  89.  
  90.     if((hhp = fopen(argv[3], "w")) == NULL){    /* problems */
  91.     perror(argv[3]);
  92.         exit(-1);
  93.     }
  94.  
  95.     fprintf(hhp,"/*\n * Pine Help text header file\n */\n");
  96.     fprintf(hhp,"\n#define\tHELP_KEY_MAX\t%d\n", HELP_KEY_MAX);
  97.     fprintf(hhp,"struct hindx {\n    char  key[HELP_KEY_MAX];");
  98.     fprintf(hhp,"\t\t/* name of help section */\n");
  99.     fprintf(hhp,"    long  offset;\t\t\t/* where help text starts */\n");
  100.     fprintf(hhp,"    short lines;\t\t\t/* how many lines there are */\n");
  101.     fprintf(hhp,"};\n\n\n/*\n * defs for help section titles\n */\n");
  102.  
  103.     index = 0L;
  104.     line  = section = 0;
  105.  
  106.     while(fgets(s, 255, hp) != NULL){
  107.     line++;
  108.     len = strlen(s);
  109.     if(s[0] == '='){            /* new section? */
  110.         i = 0;
  111.         while((s[i] == '=' || isspace((unsigned char)s[i])) && i < len)
  112.         i++;
  113.  
  114.         if(section)
  115.             fwrite(&irec, sizeof(struct hindx), 1, hip);
  116.  
  117.         irec.offset = index + (long)i;    /* save where name starts */
  118.         irec.lines = 0;
  119.         p = &irec.key[0];            /* save name field */
  120.         while(!isspace((unsigned char)s[i]) && i < len)
  121.         *p++ = s[i++];
  122.         *p = '\0';
  123.     
  124.         if(irec.key[0] == '\0'){
  125.         fprintf(stderr,"Invalid help line %d: %s", line, s);
  126.         exit(-1);
  127.         }
  128.         else
  129.           fprintf(hhp, "#define\t%s\t%d\n", irec.key, section++);
  130.  
  131.     }
  132.     else if(s[0] == '#' && section){
  133.         fprintf(stderr,"Comments not allowed in help text: line %d", line);
  134.         exit(-1);
  135.     }
  136.     else{
  137.         irec.lines++;
  138.     }
  139.     index += len;
  140.     }
  141.  
  142.     if(section)                /* write last entry */
  143.       fwrite(&irec, sizeof(struct hindx), 1, hip);
  144.  
  145.     fprintf(hhp, "#define\tLASTHELP\t%d\n", section);
  146.  
  147.     fclose(hp);
  148.     fclose(hip);
  149.     fclose(hhp);
  150. }
  151.